package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.ylbusiness.incomeability.IncomeAbilityScoreRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;


import java.io.IOException;

/**
 * 银联商务-收入能力评分
 *
 * @author guoqiang
 */

public class IncomeAbilityScoreParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 银联商务近期收入稳定性评级
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        IncomeAbilityScoreRecord obj = (IncomeAbilityScoreRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful);

        StringBuilder TxSb = new StringBuilder(500);
        TxSb.append(formatValue(obj.getMsgTp())).append(CRT001);
        TxSb.append(formatValue(obj.getMsgVer())).append(CRT001);
        TxSb.append(formatValue(obj.getTrxInfTrxDate())).append(CRT001);
        TxSb.append(formatValue(obj.getTrxInfTrxTime())).append(CRT001);
        TxSb.append(formatValue(obj.getTrxInfTrxID())).append(CRT001);
        TxSb.append(formatValue(obj.getMerInfMerID())).append(CRT001);
        TxSb.append(formatValue(obj.getSecurInfSignSN())).append(CRT001);
        TxSb.append(formatValue(obj.getSecurInfNcrptnSN())).append(CRT001);
        TxSb.append(formatValue(obj.getOrderInfTransStatus())).append(CRT001);
        TxSb.append(formatValue(obj.getOrderInfTransMsg())).append(CRT001);
        TxSb.append(formatValue(obj.getOrderInfIfFee())).append(CRT001);
        TxSb.append(formatValue(obj.getDetailSrnlScore())).append(CRT001);
        TxSb.append(formatValue(obj.getRtnInfRtnDtTm())).append(CRT001);
        TxSb.append(formatValue(obj.getRtnInfRtnSysCd())).append(CRT001);
        TxSb.append(formatValue(obj.getRtnInfRtnSysDesc())).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + TxSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_income_ability_score_inc";
    }

    @Override
    public String getType() {
        return RecordType.INCOME_ABILITY_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "银联商务-收入能力评分";
    }
}
